from flask import render_template
from app.models import News
from . import news



#视图函数

@news.route('/hello')
def hello():
    return 'hello Flask ww'

@news.route('/index')
def index():
    """ 新闻首页 """
    print('hehhhh')
    news_list = News.objects.filter(is_valid=True)
    print(news_list.count)
    return render_template("index.html", news_list=news_list)

@news.route('/cat<name>/')
def cat(name):
    """ 新闻类别页面 """
    news_list = News.objects.filter(is_valid=True, news_type=name)
    return render_template('cat.html', name=name, news_list=news_list)

@news.route('/detail/<pk>/')
def detail(pk):
    """ 新闻详情页 """
    new_obj = News.objects.filter(pk=pk).first()
    return render_template('detail.html', new_obj=new_obj)

